package com.itzz.spring_zhoneHeng.controller;


import com.itzz.spring_zhoneHeng.base.RestResponse;
import com.itzz.spring_zhoneHeng.dao.BookDao;
import com.itzz.spring_zhoneHeng.dao.BookShelfDao;
import com.itzz.spring_zhoneHeng.pojo.Book;
import com.itzz.spring_zhoneHeng.pojo.BookShelf;
import com.itzz.spring_zhoneHeng.service.BookShelfService;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/bookshelf")
public class BookShelfController {

    @Autowired
    BookShelfService bookShelfService;

    @Autowired
    BookShelfDao bookShelfDao;



    //查询所有的书架书籍
    @RequestMapping("/queryAllBookShelf")
    public RestResponse queryAllBook(BookShelf bookShelf,Integer pageNum,
                                     Integer pageSize,Integer userid){
        RestResponse response = bookShelfService.queryAllBookShelf(bookShelf, pageNum, pageSize,userid);
        return response;
    }

    //查询BookshelfId查询书籍
    @RequestMapping("/queryAllByBookShelfId/{bookShelfId}")
    public RestResponse queryAllBook(@PathVariable("bookShelfId") Integer bookShelfId){
        RestResponse response = bookShelfService.queryBookShelfById(bookShelfId);
        return response;
    }




    //根据删除书架书籍   (修改书籍的书架状态)
    @RequestMapping("/delete/{id}")
    public RestResponse delete(@PathVariable("id") Integer id, Integer bookshelf){

        RestResponse response = bookShelfService.deleteBook(id);
        return response;
    }

    //添加书籍到书架  (普通会员限定)    (也是一样的修改书籍的书架状态 以及添加到书架)
    @RequestMapping("/add/{userId}")
    public RestResponse add(BookShelf bookShelf,Integer id, Integer bookshelf,@PathVariable("userId") Integer userId){
        RestResponse response = bookShelfService.addBook(bookShelf,id, bookshelf,userId);
        return response;
    }

    //添加书籍到书架   (会员限定)
//    @RequestMapping("/addMemberBook")
//    @PreAuthorize("hasRole('ROLE_novelAddAll')")
//    public RestResponse addBook(BookShelf bookShelf, Integer id, Integer bookshelf){
//        RestResponse response = bookShelfService.addBook(bookShelf,id, bookshelf);
//        return response;
//    }

    //判断我前台点击的书是否存在于我的书架中
    @RequestMapping("/queryBookShelf")
    public RestResponse queryBookShelf(Integer userId,Integer bookId){
        RestResponse response = bookShelfService.queryBookShelf(userId,bookId);
        return response;
    }

    //根据bookshelfId 查询表 b_bs表的 bookid
    //queryBookIdByBsid   /bookshelf/queryBookIdByBsid/{bsId}
    @RequestMapping("/queryBookIdByBsid/{bsId}")
    public RestResponse queryBookIdByBsid(@PathVariable("bsId")Integer bsId) {
        RestResponse response = bookShelfService.queryBookIdByBsid(bsId);

        return  response;
    }






}
